import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:identification_photo/config/network_config.dart';
import 'package:identification_photo/config/sp_name.dart';
import 'package:identification_photo/utils/cache_util.dart';
import 'package:identification_photo/utils/format_util.dart';
import 'package:identification_photo/utils/string_util.dart';

//Option拦截器可以用来统一处理Option信息 可以在这里添加
class OptionInterceptor extends InterceptorsWrapper {
  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    String? mainUrl = CacheUtil().get<String>(SPName.mainUrl);
    if (StringUtil.isNotEmpty(mainUrl)) {
      options.baseUrl = mainUrl!;
    } else {
      options.baseUrl = NetworkConfig.baseUrl;
    }
    debugPrint(
        "request:---->${options.method}\t url-->${options.baseUrl}${options.path}?${FormatUtil.formattedUrl(options.queryParameters)}");

    if (options.queryParameters["hideLoading"] != true) {
      EasyLoading.show();
    }
    return handler.next(options);
  }
}
